Accord Software, Inc.

tutorial05/main.c




/*
 * Accord Software, Inc.
 *
 * Tutorial 05
 *
 * send a tree
 */

#include "tree.h"

/* build a tree with a number in the node */

static struct tnode t[] = {
	{ 1, &t[ 1], &t[ 2]},   /*  1 */
	{ 2, &t[ 3], &t[ 4]},   /*  2 */
	{ 9, &t[ 5], &t[ 6]},   /*  3 */
	{ 3, &t[ 7], &t[ 8]},   /*  4 */
	{ 6, &t[ 9], &t[10]},   /*  5 */
	{10, &t[11], &t[12]},   /*  6 */
	{13, &t[13], &t[14]},	/*  7 */
	{ 4, 0     , 0     },	/*  8 */
	{ 5, 0     , 0     },	/*  9 */
	{ 7, 0     , 0     },	/* 10 */
	{ 8, 0     , 0     },	/* 11 */
	{11, 0     , 0     },	/* 12 */
	{12, 0     , 0     },	/* 13 */
	{14, 0     , 0     },	/* 14 */
	{15, 0     , 0     },	/* 15 */
};

/* build a tree with a token in the node */

static struct strnode p[] = {
	{0, &p[1], &p[2]},      /* 0 */
	{0, &p[3], &p[4]},      /* 1 */
	{0, &p[5], &p[6]},      /* 2 */
	{0, &p[7], &p[8]},      /* 3 */
	{0, &p[9], &p[10]},     /* 4 */
	{0, 0    , 0    },      /* 5 */
	{0, 0    , 0    },      /* 6 */
	{0, 0    , 0    },      /* 7 */
	{0, 0    , 0    },      /* 8 */
	{0, 0    , 0    },      /* 9 */
	{0, 0    , 0    },      /* 10 */
};

main(argc, argv)
	int argc;
	char *argv[];
{
	struct tnode *tp;
	char *s = argv[0];

	/*
	 * send the whole tree starting from root, 
	 * i.e. 1 thru 15
	 */
	
	printf("%s sum 1 to 15 = %d\n", s, tsum(&t[0]));
	
	p[0].token = "one";    p[1].token = "two";
	p[2].token = "eight";  p[3].token = "three";
	p[4].token = "six";    p[5].token = "nine";
	p[6].token = "ten";    p[7].token = "four";
	p[8].token = "five";   p[9].token = "seven";

	tokenprint(p);
}

[ Home | Tutorials | tree.c | tree.h ]
E-Mail:webmaster@accord.com
[P-026] Updated March 14, 1996
Copyright © 1993-1996 Accord Software, Inc. All rights reserved.